# -*- encoding: utf-8 -*-
require 'net/http'

Oj.mimic_JSON

module Faye
  class Client
    def self.send(channel, params, url='http://localhost:8080/faye')
      Thread.new {
        message = Oj.dump({ channel: channel, data: params })
            uri = URI.parse(url)

        req = Net::HTTP.post_form(uri, message: message)
        puts Oj.load(req.body) rescue req.body
      }
    end
  end
  # curl http://localhost:8080/faye -d 'message={"channel":"/notifications/test", "data":"hello"}'
end